package wordit.impl.letterCells;

import wordit.Dictionary;
import wordit.Game;
import wordit.ea.Configuration;
import wordit.ea.EvolutionaryAlgorithm;
import wordit.ea.selectionfunctions.TournamentSelectionFunction;
import wordit.ea.stopfunctions.MaximumGenerationsStopFunction;
import wordit.impl.DataListener;
import wordit.impl.PlainTextDictionary;

public class Runner {

	public static void main(String[] args) throws Exception {
		Game game = new Game("config/game02.config");
		Dictionary dictionary = new PlainTextDictionary("config/dictionary.txt");
		//Validator.setGame(game);

		Configuration config = new Configuration();
		config.setGenerationSize(100);
		config.setCrossoverFunction(new LetterCellCrossover(game));
		config.setFitnessFunction(new LetterCellFitness(dictionary));
		config.setGenomeFactory(new LetterCellGenomeFactory(game));
		config.setMutationFunction(new LetterCellMutation(game, 0.01));
		config.setSelectionFunction(new TournamentSelectionFunction(4));
		config.setStopFunction(new MaximumGenerationsStopFunction(50));
		config.setTrialsCount(5);
		config.readFromArguments(args);

		//Validator.setEnabled(false);
		System.err.printf("Using configuration:\n%s\n", config);

		EvolutionaryAlgorithm ea = new EvolutionaryAlgorithm(config);
		DataListener dataListener = new DataListener();
		ea.addEvolutionaryAlgorithmListener(dataListener);

		for (int i = 0; i < config.getTrialsCount(); ++i)
			ea.run();

		dataListener.onAllTrialsDone();
	}
}